package initialize

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	_ "github.com/mbobakov/grpc-consul-resolver" // It's important
	"go.uber.org/zap"
	"project_api/user_web/global"
)

func InitRedisConn() {
	var ctx = context.Background()
	global.RedisDb = redis.NewClient(&redis.Options{
		Addr:     fmt.Sprintf("%s:%d", global.ServerConfig.RedisInfo.Host, global.ServerConfig.RedisInfo.Port),
		Password: global.ServerConfig.RedisInfo.Pass, // no password set
		DB:       0,                                  // use default DB
	})

	_, err := global.RedisDb.Ping(ctx).Result()
	if err != nil {
		zap.S().Fatal("[InitRedisConn] 连接 【redis连接失败】")
	}
}
